package com.asia5b.a5mall.middleware.utils;

import android.text.TextUtils;

import com.asia5b.a5mall.middleware.base.BaseApplication;



/**
 * Created by zhangyuncai on 2019/9/9.
 * 常用正则表达式
 */
public class WValidatorUtil {
    /**
     * 是否是手机号码
     *
     * @param phoneNumber 手机号码
     * @param countryCode 国家区号
     * @return
     */
    public static boolean isPhoneNumber(String phoneNumber, String countryCode) {
        if (!TextUtils.isEmpty(countryCode) && countryCode.length() >= 2) {
            if (!TextUtils.isEmpty(phoneNumber) && phoneNumber.length() >= 7) {
                return true;
            }
        }
//        try {
//            if (TextUtils.isEmpty(phoneNumber) || TextUtils.isEmpty(countryCode)) {
//                return false;
//            }
//            PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.createInstance(BaseApplication.sContext);
//            long phoneNumberL = Long.parseLong(phoneNumber);
//            int countryCodeI = Integer.parseInt(countryCode);
//            Phonenumber.PhoneNumber pn = new Phonenumber.PhoneNumber();
//            pn.setCountryCode(countryCodeI);
//            pn.setNationalNumber(phoneNumberL);
//            return phoneNumberUtil.isValidNumber(pn);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        return false;
    }

    /**
     * 是否是手机号码
     *
     * @param phoneNumber 手机号码
     * @return
     */
    public static boolean isPhoneNumber2(String phoneNumber) {
        String strPattern = "^[0-9]{8,15}$";
        if (TextUtils.isEmpty(strPattern)) {
            return false;
        } else {
            return phoneNumber.matches(strPattern);
        }
    }

    /**
     * 邮箱是否正确
     *
     * @param strEmail
     * @return
     */
    public static boolean isEmail(String strEmail) {
        String strPattern = "^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
        if (TextUtils.isEmpty(strPattern)) {
            return false;
        } else {
            return strEmail.matches(strPattern);
        }
    }

    /**
     * 邮箱是否正确
     *
     * @param strEmail
     * @return
     */
    public static boolean isEmail2(String strEmail) {
        String strPattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
        if (TextUtils.isEmpty(strPattern)) {
            return false;
        } else {
            return strEmail.matches(strPattern);
        }
    }

    /**
     * 固话是否正确
     *
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        String strPattern = "0\\d{2,3}-\\d{7,8}";
        if (TextUtils.isEmpty(strPattern)) {
            return false;
        } else {
            return phone.matches(strPattern);
        }
    }

    /**
     * 纳税识别号
     *
     * @param distinguish
     * @return
     */
    public static boolean isDistinguish(String distinguish) {
        String strPattern = "(^[a-zA-Z0-9]{15}$)|(^[a-zA-Z0-9]{18}$)|(^[a-zA-Z0-9]{20}$)";
        if (TextUtils.isEmpty(strPattern)) {
            return false;
        } else {
            return distinguish.matches(strPattern);
        }
    }

    /**
     * 身份证
     *
     * @param legalId
     * @return
     */
    public static boolean isLegalId(String legalId) {
        String strPattern = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$";
        if (TextUtils.isEmpty(strPattern)) {
            return false;
        } else {
            return legalId.matches(strPattern);
        }
    }
}

/*
// 手机号
export const mobile = /^[0-9]{8,15}$/

// 电子邮箱
export const email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/

// 密码【6-20位 包括特殊字符】
export const password = /^[A-Za-z0-9!#$%^&*.~,]{6,20}$/

// 正整数【不包含0】
export const integer = /^[1-9]\d*$/

// 金钱
export const money = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/

// 纳税识别号
// export const TINumber = /^\d{15}$|^\d{18}$|^\d{20}$/
export const TINumber = /(^[a-zA-Z0-9]{15}$)|(^[a-zA-Z0-9]{18}$)|(^[a-zA-Z0-9]{20}$)/

// 身份证
export const IDCard = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/

// 账户名称【汉字、字母、数字、“-”、“_”的组合】以其开头并且匹配一个或任意多个
export const userName = /^[A-Za-z0-9_\-\u4e00-\u9fa5]+$/

// URL
export const URL = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/

// 固话
export const TEL = /0\d{2,3}-\d{7,8}/
 */